<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/vue.js"></script>
    <style>
        li.active{
            background-color: aqua;
        }
    </style>
</head>
<body>
    <div id="app">
        <input type="text" v-model="kw" @keydown.down="toDown" @keydown.up.prevent="toUp">
        <ul>
            <li v-for="(item,index) of arr" :key="index" :class="[index==n?'active':'']">{{item[0]}}</li>
        </ul>
    </div>
    <script>
        let vm =new Vue({
            el: "#app",
            data: {
                kw:'',
                arr:[],
                n:-1,
            },
            methods: {
                toDown(){
                    this.n++;
                    if(this.n>this.arr.length-1){
                        this.n=-1;
                    }
                },
                toUp(){
                    this.n--;
                    if(this.n<0){
                        this.n=this.arr.length;
                    }
                }
            },
            watch:{
                kw(){
                   if(this.kw == ''){
                       this.arr=[];
                        return;
                   }
                   let scr = document.createElement('script');
                   scr.src=`https://suggest.taobao.com/sug?q=${this.kw}&callback=callback&code=utf-8`;
                   document.body.appendChild(scr);
                }
            }
        })
        function callback(res){
           vm.arr=res.result;
        }
    </script>
</body>

</html>